package com.xl.bigdata.es.sql;

import org.elasticsearch.xpack.sql.jdbc.EsDataSource;

import java.sql.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;


/*
 * POST /_license/start_trial?acknowledge=true
 *
 * SQL JDBC没有学习版开发所有权限，还是提供了试用的，我们只需要开启授权后也能免费使用30
 */
public class SqlAPI {


    public static void jdbc() throws SQLException {
        EsDataSource dataSource = new EsDataSource();
        String address = "jdbc:es://10.155.20.101:49200";
        dataSource.setUrl(address);
        Properties connectionProperties = new Properties();
        connectionProperties.setProperty("user","elastic");
        connectionProperties.setProperty("password","123456");
        dataSource.setProperties(connectionProperties);
        Connection connection = dataSource.getConnection();
        PreparedStatement ps = connection.prepareStatement("select * from workorder_photo_v1 limit 10");
        ResultSet resultSet = ps.executeQuery();
        List<String> result = new ArrayList<String>();
        while (resultSet.next()) {
            System.out.println(resultSet.getString("branch_name"));
        }
        ps.close();
        connection.close();
    }


    public static void main(String[] args) {
        try {
            jdbc();
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }

    }
}
